package cn.javass.dp.decorator.example2;

import java.util.Date;

/**
 * 计算奖金的对象
 */
public class Prize {
    public double calcPrize(String user, Date begin, Date end) {
        double prize = 0.0;

        //计算当月义务奖金，所有人都会计算
        prize = this.monthPrize(user, begin, end);

        prize += this.sumPrize(user, begin, end);

        if (this.isManager(user)) {
            prize += this.groupPrize(user, begin, end);
        }
        return prize;
    }


    private double monthPrize(String user, Date begin, Date end) {
        double prize  = TempDB.mapMonthSaleMoney.get(user) * 0.03 ;
        System.out.println("当月奖金："+prize);
        return prize;
    }

    /**
     * 计算团队业务奖金
     * @param user
     * @param begin
     * @param end
     * @return
     */
    private double groupPrize(String user, Date begin, Date end) {
        double group = 0.0;
        for (double d : TempDB.mapMonthSaleMoney.values()) {
            group += d;
        }
        double prize = group * 0.01;
        System.out.println("当月团队业务奖金："+prize);
        return prize;
    }

    private boolean isManager(String user) {
        if ("王五".equals(user)) {
            return true;
        }
        return false;
    }

    private double sumPrize(String user, Date begin, Date end) {
        double prize = 1000000 * 0.001;
        System.out.println("累计奖金："+prize);
        return prize;
    }

}
